<?php require_once ADMINVIEWPATH.'admin_header.php'; ?>
<?php require_once ADMINVIEWPATH.'admin_menu.php'; ?>
<style type="text/css">
    input[type="checkbox"], input[type="radio"] {
    cursor: pointer;
    opacity: 1;
    position: static;
    z-index: 12;
}
</style>
<div class="page-content">
    <!-- Page Breadcrumb -->
    <div class="page-breadcrumbs">
        <ul class="breadcrumb">
            <li>
                <i class="fa fa-home"></i>
                <a href="/luckydog/index">首页</a>
            </li>
            <li >
                <a href="#">转盘活动</a>
            </li>
            <li class="active">
                月度/年度抽奖管理
            </li>
        </ul>
    </div>
    <!-- Page Body -->
    <div class="page-body">
        <div class="row">
            <div class="col-xs-12 col-md-12">
                <div class="tab-content tabs-flat no-padding">
                    <div id="visits" class="tab-pane active animated fadeInUp">
                        <div class="row">
                            <div class="col-lg-12 chart-container">
                                <div id="dashboard-chart-visits" class="chart chart-lg no-margin">
                                    <div class="widget-body">
											<div style="float: left;">
												<div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">开始时间：</div>
												<input class="form-control" style="width:100px;" type="text" placeholder="起始时间" id="starttime" onClick="WdatePicker({maxDate:'#F{$dp.$D(\'endtime\')||\'2120-10-01\'}'})" value="<?=$starttime?>">
											</div>
											<div style="float: left;">
												<div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">结束时间：</div>
												<input class="form-control" style="width:100px;" type="text" placeholder="起始时间" id="endtime" onClick="WdatePicker({minDate:'#F{$dp.$D(\'starttime\')}',maxDate:'2120-10-01'})" value="<?=$endtime?>">
											</div>
                                            <div class="control-group"  style="float: left; padding-left:10px;">
                                                <div class="controls" >
                                                状态：
                                                    <select id="status" style="width: 100px;">
                                                        <option value = "0">--全部--</option>
                                                        <option <?php if($status == 1):?> selected="selected"<?php endif;?> value = "1">当前抽奖人员</option>
                                                        <option <?php if($status == 2):?> selected="selected"<?php endif;?> value = "2">历史抽奖人员</option>
                                                    </select>
                                                </div>
                                            </div>
									
											<div style="float: left;">
												<a class="btn J_search" href="javascript:;">搜索</a>
												
											</div>
											
											<div class="pull-right js_batch_show" style="clear:both;<?php if($status):?>display:none;<?php endif;?>">批量设置∨</div>
											 <div class="box-header with-border batch_place" style="display:none;">
											  <div class="form-group pull-left" style="margin-left: 10px;">
												<label>
												  <input  type="checkbox" class="all"  value='' />全选
												</label>
											  </div>
											 <div style="float: left;">
                                                <div class="pull-left" style="line-height: 30px;margin-left: 10px;margin-bottom: 20px;">抽奖批次：</div>
                                                <input class="form-control" style="width:100px;" type="text" placeholder="起始时间" id="current_batch" onClick="WdatePicker()" value="">
                                            </div>
											  <div class="form-group pull-left" style="width: 150px;margin-left:10px;">
												<button type="button" class="btn btn-block btn-primary js_batch">执行批量操作</button>
											  </div>

                                              <div class="form-group pull-left" style="width: 150px;margin-left:10px;">
                                                <button type="button" class="btn btn-block btn-primary js_setempty">清空月/年终抽奖</button>
                                              </div>
											</div>
                                            <table class="table table-striped table-bordered table-hover" id="simpledatatable">
                                                <thead>
                                                    <tr class="add_th">
                                                        <th>用户ID</th>
                                                        <th>账号</th>
                                                        <th>昵称</th>
                                                        <th>性别</th>
														<th>答软文数/参加天数</th>
                                                       <th>操作</th> 
                                                    </tr>
                                                </thead>
                                                <?php if(!empty($userList)):?>
                                                    <?php foreach($userList as $key=> $row):?>
                                                        <tr userselected="<?=$row['userselected']?>" class="gradeX <?php if(!$row['userselected']):?>add_td<?php else:?>add_td_empty<?php endif;?>" data_id = "<?php echo $row['AccountID'];?>">
                                                            <td class="center" style="text-align:center;width:40px;"><?php echo $row['AccountID']?></td>
                                                            <td class="center"><?=$row['username']?></td>
                                                            <td class="center"><?=$row['nickname']?></td>
                                                            <td class="center"><?=$row['sex']==1?"男":"女"?><?=$row['age']?></td>
															<td class="center"><?=$row['jointcnt'].'/'.$row['jointdaycnt']?></td>
                                                            <td class="center " status="<?php echo $row['Status']?>" data_id = "<?php echo $row['year_month_id'];?>">
                                                                <!-- <a href="javascript:;" class="edit_account">详情</a>&nbsp;|&nbsp; -->
                                                                <?php if($status == 1):?><a href="javascript:;" class="J_del">删除</a><?php endif;?>
                                                                
                                                                
                                                            </td>
                                                        </tr>
                                                    <?php endforeach;?>
                                                <?php endif;?>
                                                <tr>
                                                    <td align='center' colspan="21"> <div class="page_links"><?= $page_links?></div></td>
                                                </tr>
                                            </table>
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="<?php echo STATICURL; ?>js/jquery-2.0.3.min.js"></script>
<script src="<?php echo STATICURL; ?>layer/layer.js"></script>
<script src="<?= STATICURL; ?>js/wdatepicker/WdatePicker.js"></script>
<?php require_once ADMINVIEWPATH.'admin_footer.php'; ?>
<script>
    $('.edit_account').on('click', function(){
        //iframe窗
        var id = $(this).parent().attr("data_id");
        layer.open({
            type: 2,
            title: "查看",
            shadeClose: true,
            shade: [0.5, '#000'],
            maxmin: true, //开启最大化最小化按钮
            area: ['750px', '520px'],
            content: '/luckydog/user/touUserInfo?id='+id
        });
    });
$('.js_batch_show').click(function(){
  $('.batch_place').slideToggle('fast','linear',function(){
    var _html = '<td class="center" ><input  class="duoxuan" type="checkbox" name="duoxuan"  /></td>';
    var _html_empty = '<td class="center" >已选</td>';
    var _duoxuan = $(".duoxuan").html();
    if(_duoxuan == undefined)
    {
      $(".add_th").prepend("<th class='empty_th'></th>");
      $(".add_td").prepend(_html);  
      $(".add_td_empty").prepend(_html_empty);  
      
    }else{
      $(".empty_th").remove();
      $(".add_td").find('.duoxuan').parent().remove();
    }
  });
});
$('.all').click(function(){
    if($(this).prop("checked")){
        $("input[name='duoxuan']").prop('checked',true);
    }else{
        $("input[name='duoxuan']").prop('checked',false);
    }
});

$(".js_batch").click(function(){
    var chooseuser  = new Array();
    var current_batch = $("#current_batch").val();
    if(current_batch == "")
    {
        layer.msg("抽奖批次不能为空");
        return false;
    }
    $(".duoxuan").each(function(index,item){
        if($(this).prop("checked")){
                var AccountID = $(this).parent().parent().attr("data_id");
                if(AccountID && AccountID != 'undefined')
                {
                    chooseuser.push(AccountID);
                }
                
        }
    });
    if(chooseuser.length)
    {
        if(confirm("确定要添加吗"))
        {
            $.post("/luckydog/luckydraw/addLuckydrawUser",{chooseuser:chooseuser,current_batch:current_batch},function(data){
                if(data)
                {
                    layer.msg("成功");
                    window.location.reload();
                }
            });
        }
       
    }
    console.log(chooseuser);
});

$(".J_del").click(function(){
    if(confirm("确定要删除吗"))
    {
        var id=$(this).parent().attr("data_id");
        $.post("/luckydog/luckydraw/deleteLuckydrawUser",{id:id},function(data){
            if(data)
            {
                layer.msg("成功");
                window.location.reload();
            }
        });
    }
});
$(".js_setempty").click(function(){
    if(confirm("确定要清空吗"))
    {
        $.post("/luckydog/luckydraw/deleteLuckydrawUser",{},function(data){
            if(data)
            {
                layer.msg("成功");
                window.location.reload();
            }
        });
    }
});

    $(document).ready(function() {
		$(".J_search").click(function(){
			var endtime = $("#endtime").val();
			var starttime = $("#starttime").val();
			var status = $("#status").val();
			var params={
				'starttime':starttime,
				'endtime':endtime,
				'status':status,
			};
		   location = "/luckydog/luckydraw/chooseUser?"+$.param(params);
		});
    });

</script>
